*Recoding ZA2809

use "Data\ZA2809\ZA2809.dta" , clear

*Support for democracy
gen $idea_democracy			= V17

*Support for liberal democracy
	*not included in dataset

*define missing values
	*already defined 
*recode missing values 

*Efficacy
gen $politicians_takecare = V52
gen $politicians_interestpublic = V55
	
*Standardize range from 0 to 1; higher values indicate higher support for democracy
replace $idea_democracy =  (6-$idea_democracy)/5  if !missing($idea_democracy)
replace $politicians_takecare = ($politicians_takecare - 1) / 3  if !missing($politicians_takecare)
replace $politicians_interestpublic = (4 - $politicians_interestpublic) / 3  if !missing($politicians_interestpublic)


*Sociodemographic Controls
gen		$gender 			= V148-1

gen 	$age				= V151

gen 	$education			= V152
replace $education 			= 0 if $education <= 6 | $education == 8  // still at school, none, Hauptschule, mittlere Reife = 0
replace $education 			= 1 if $education == 7					  // Abitur/EOS mit Abschluss = 1

gen $eastwest 				= V194-1



*Party ID
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyid_category		= 1 	if inlist(V147, 1, 3)
replace $partyid_category	= 0 	if inlist(V147, 2, 4, 5, 10)
replace $partyid_category	= -1 	if inlist(V147, 6, 7, 8, 9, 11, 12)

*Party Vote
*Did R lean towards  a left, right or other party?
*1: right, (CDU/CSU, FDP, AfD), 0: left (Left/PDS, Greens, SPD), -1: other
gen $partyvote_category		= 1 	if inlist(V169, 1, 3)
replace $partyvote_category	= 0 	if inlist(V169, 2, 4, 5, 10)
replace $partyvote_category	= -1 	if inlist(V169, 6, 7, 8, 9, 11, 12)


*Meta variables
gen $dataset 					= "ZA2809"
gen $year 						= 1992
									 
*weight
gen weight = 1

tab $idea_democracy V17, m  //check
tab $gender V148, m
tab $age V151, m
tab $education V152, m
tab $eastwest V194, m

*Save recode dataset
keep $idea_democracy $politicians_takecare $politicians_interestpublic $gender $age $education $eastwest $dataset $year  weight	$partyid_category	$partyvote_category	
save ZA2809_recoded.dta, replace
